{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Valid Palindrome"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #two-pointers #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #双指针 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: isPalindrome"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #验证回文串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>如果在将所有大写字符转换为小写字符、并移除所有非字母数字字符之后，短语正着读和反着读都一样。则可以认为该短语是一个 <strong>回文串</strong> 。</p>\n",
    "\n",
    "<p>字母和数字都属于字母数字字符。</p>\n",
    "\n",
    "<p>给你一个字符串 <code>s</code>，如果它是 <strong>回文串</strong> ，返回 <code>true</code><em> </em>；否则，返回<em> </em><code>false</code><em> </em>。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入:</strong> s = \"A man, a plan, a canal: Panama\"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>\"amanaplanacanalpanama\" 是回文串。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \"race a car\"\n",
    "<strong>输出：</strong>false\n",
    "<strong>解释：</strong>\"raceacar\" 不是回文串。\n",
    "</pre>\n",
    "\n",
    "<p><strong>示例 3：</strong></p>\n",
    "\n",
    "<pre>\n",
    "<strong>输入：</strong>s = \" \"\n",
    "<strong>输出：</strong>true\n",
    "<strong>解释：</strong>在移除非字母数字字符之后，s 是一个空字符串 \"\" 。\n",
    "由于空字符串正着反着读都一样，所以是回文串。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>1 &lt;= s.length &lt;= 2 * 10<sup>5</sup></code></li>\n",
    "\t<li><code>s</code> 仅由可打印的 ASCII 字符组成</li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [valid-palindrome](https://leetcode.cn/problems/valid-palindrome/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [valid-palindrome](https://leetcode.cn/problems/valid-palindrome/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"A man, a plan, a canal: Panama\"', '\"race a car\"', '\" \"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s, i, j):\n",
    "        while (i < j):\n",
    "            \n",
    "            if s[i] != s[j]:\n",
    "                return False\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        return True\n",
    "    def validPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        \n",
    "        i = -1\n",
    "        j = len(s)\n",
    "        while (i < j):\n",
    "            i += 1\n",
    "            j -= 1\n",
    "\n",
    "            if (s[i] != s[j]):\n",
    "                return self.isPalindrome(s, i+1, j) or self.isPalindrome(s, i, j-1)\n",
    "        \n",
    "        return True\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def validPalindrome(self, s: str) -> bool:\n",
    "        i = 0\n",
    "        j = len(s) - 1\n",
    "        while i < j:\n",
    "            if s[i] != s[j]:\n",
    "                return (self.isPalindrome(s,i+1,j) or self.isPalindrome(s, i,j-1))\n",
    "            i+=1\n",
    "            j-=1\n",
    "        return True\n",
    "\n",
    "    def isPalindrome(self, s: str, i: int, j: int) -> bool:\n",
    "        while(i < j):\n",
    "            if s[i] == s[j]:\n",
    "                i += 1\n",
    "                j -= 1\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isValidPalindrome(self, s: str, k: int) -> bool:\n",
    "        t = s[::-1]\n",
    "        l = len(s)\n",
    "\n",
    "        dp = [[0] * (l + 1) for _ in range(l + 1)]\n",
    "\n",
    "        for i in range(1, l + 1):\n",
    "            for j in range(1, l + 1):\n",
    "                if s[i - 1] == t[j - 1]:\n",
    "                    dp[i][j] = dp[i - 1][j - 1] + 1\n",
    "                else:\n",
    "                    dp[i][j] = max(dp[i - 1][j], dp[i][j - 1])\n",
    "        \n",
    "        return (l - dp[l][l]) <= k\n",
    "\n",
    "\n",
    "    # def isValidPalindrome(self, s: str, k: int) -> bool:\n",
    "    #     l = len(s)\n",
    "    #     dp = [[[True if i == j else False] * (k + 1) for j in range(l + 1)] for i in range(l + 1)]\n",
    "\n",
    "    #     def isPalindrome(word):\n",
    "    #         l = len(word) // 2\n",
    "    #         for i in range(l):\n",
    "    #             if word[i] != word[len(word) - 1 - i]:\n",
    "    #                 return False\n",
    "    #         return True\n",
    "\n",
    "    #     for i in range(l, 0, -1):\n",
    "    #         for j in range(i, l + 1):\n",
    "    #             for t in range(k + 1):\n",
    "    #                 max_len = j - i + 1\n",
    "    #                 if t > max_len:\n",
    "    #                     dp[i][j][t] = True\n",
    "    #                     continue\n",
    "    #                 if t == 0:\n",
    "    #                     word = s[i - 1:j + 1 - 1]\n",
    "    #                     dp[i][j][t] = isPalindrome(word)\n",
    "    #                 else:\n",
    "    #                     if i == j:\n",
    "    #                         continue\n",
    "    #                     if s[i - 1] == s[j - 1]:\n",
    "    #                         dp[i][j][t] = dp[i + 1][j - 1][t]\n",
    "    #                     else:\n",
    "    #                         dp[i][j][t] = dp[i][j - 1][t - 1] or dp[i + 1][j][t - 1]\n",
    "    #     return dp[1][l][k]\n",
    "                    \n",
    "                \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        char_list =  [ c for c in str.lower(s) if c.isalnum() ]\n",
    "        i = 0\n",
    "        j = len(char_list) - 1\n",
    "        while i <= j:\n",
    "            if char_list[i] == char_list[j]:\n",
    "                i = i+1\n",
    "                j = j-1\n",
    "            else:\n",
    "                return False\n",
    "        return True\n",
    "\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: 'str') -> 'bool':\n",
    "        \n",
    "        def to_lower(c):\n",
    "            if c >= 'a' and c <= 'z' or c >= '0' and c <= '9':\n",
    "                return c\n",
    "            if c >= 'A' and c <= 'Z':\n",
    "                return chr(ord(c) - ord('A') + ord('a'))\n",
    "\n",
    "                \n",
    "        \n",
    "        if s == '':\n",
    "            return True\n",
    "        n = len(s)\n",
    "        i, j = 0, n - 1\n",
    "        while i < j:\n",
    "            l, r = to_lower(s[i]), to_lower(s[j])\n",
    "            if not l:\n",
    "                i += 1\n",
    "            elif not r:\n",
    "                j -= 1\n",
    "            else:\n",
    "                if l == r:\n",
    "                    i, j = i + 1, j - 1\n",
    "                else:\n",
    "                    return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        if not len(s):\n",
    "            return True\n",
    "        newStr = ''\n",
    "        for ch in s:\n",
    "            if ch.isalpha() or ch.isdigit():\n",
    "                newStr += ch\n",
    "        lenthOfNewStr = len(newStr)\n",
    "        for i in range(lenthOfNewStr//2):\n",
    "            if newStr[i].lower()!=newStr[lenthOfNewStr-i-1].lower():\n",
    "                return False\n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        l = 0\n",
    "        r = len(s) - 1\n",
    "        while l < r:\n",
    "            if not s[l].isalnum():\n",
    "                l += 1\n",
    "                continue\n",
    "            if not s[r].isalnum():\n",
    "                r -= 1\n",
    "                continue\n",
    "            if s[l].lower() != s[r].lower():\n",
    "                return False\n",
    "            else:\n",
    "                l += 1\n",
    "                r -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        if not s or not len(s):\n",
    "            return True\n",
    "        s = s.lower()\n",
    "        p, q = 0, len(s)-1\n",
    "        while p < q:\n",
    "            if not s[p].isalnum():\n",
    "                p += 1\n",
    "                continue\n",
    "            if not s[q].isalnum():\n",
    "                q -= 1\n",
    "                continue\n",
    "            if s[p] == s[q]:\n",
    "                p += 1\n",
    "                q -= 1\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        def isChar(char):\n",
    "            if (ord(char) >= ord('a') and ord(char) <= ord('z')) or (ord(char) >= ord('0') and ord(char) <= ord('9')):\n",
    "                return True\n",
    "            else:\n",
    "                return False\n",
    "        s = s.lower()       \n",
    "        if len(s) == 0:\n",
    "            return True\n",
    "        left = 0\n",
    "        right = len(s) - 1\n",
    "        print(isChar('0'))\n",
    "        print(isChar('p'))\n",
    "\n",
    "        while left <= right:\n",
    "            if isChar(s[left]) and isChar(s[right]):\n",
    "                if s[left] == s[right]:\n",
    "                    left += 1\n",
    "                    right -= 1\n",
    "                    continue\n",
    "                    \n",
    "                else:\n",
    "                    return False\n",
    "            else:\n",
    "                if not isChar(s[left]):\n",
    "                    left += 1\n",
    "                    continue\n",
    "                if not isChar(s[right]):\n",
    "                    right -= 1\n",
    "                    continue                \n",
    "                \n",
    "                \n",
    "        return True\n",
    "    \n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: 'str') -> 'bool':\n",
    "        s=re.sub(\"[^0-9a-zA-Z]+\",'',s).lower()\n",
    "        return s==s[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        s = s.lower()\n",
    "        s = re.sub(\"[^0-9a-z]\", \"\", s)\n",
    "        print(s)\n",
    "        j = len(s)\n",
    "        #print(s, [s[k] == s[j-k+0] for k in range(1, j)])\n",
    "        return all(s[k] == s[j-k-1] for k in range(0, j-1))\n",
    "    \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "import string\n",
    "\n",
    "\n",
    "class Solution:\n",
    "\tdef isPalindrome(self, s):\n",
    "\t\t\"\"\"\n",
    "\t\t:type s: str\n",
    "\t\t:rtype: bool\n",
    "\t\t\"\"\"\n",
    "\n",
    "\t\ts = re.sub(\"[^0-9a-z]\", \"\", s.lower())\n",
    "\t\treturn s == s[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        t=\"\".join(i for i in s if i.isalnum())\n",
    "        t=t.lower()\n",
    "        return t==t[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        new_s = [i for i in s.upper() if i.isalnum()]\n",
    "        error = 0\n",
    "        l = 0\n",
    "        r = len(new_s)-1\n",
    "\n",
    "        while l<r:\n",
    "            if new_s[l] != new_s[r]:\n",
    "                error = 1 \n",
    "            l+=1\n",
    "            r-=1 \n",
    "\n",
    "        return (error==0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        s = list(filter(str.isalnum, s.lower()))  #将字符转换为小写，过滤出只含字母和数据的字符\n",
    "        print(s)\n",
    "        return True if s == s[::-1] else False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        # Python isalnum() 方法检测字符串是否由字母和数字组成\n",
    "        new_s = [i for i in s.upper() if i.isalnum()]\n",
    "        # a[i:j:s]  s表示步进，缺省为1\n",
    "        # a[i:j:1] == a[i:j]\n",
    "        # a[::-1] 回文序列\n",
    "        return new_s == new_s[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        l = 0\n",
    "        r = len(s)-1\n",
    "        while l<r:\n",
    "#            print(l,r,ord(s[l].lower()),\n",
    "#                  ord(s[r].lower()))\n",
    "            while l<len(s)-1 and (not 97<=ord(s[l].lower())<=122 ) and  (not 48<=ord(s[l].lower())<=57 ):\n",
    "                print('a')\n",
    "                l+=1\n",
    "            while r>0 and (not 97<=ord(s[r].lower())<=122) and  (not 48<=ord(s[r].lower())<=57 ):\n",
    "                print('b')\n",
    "                r-=1\n",
    "            if l>=r:\n",
    "              print('h')\n",
    "              return True\n",
    "            if s[l].lower()!=s[r].lower():\n",
    "                return False\n",
    "            print(s[l].lower(),s[r].lower())\n",
    "            l+=1\n",
    "            r-=1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        end = len(s) -1\n",
    "        start = 0\n",
    "        \n",
    "        while(start < end):\n",
    "            print(s[start])\n",
    "            while( not s[start].isalpha() and not s[start].isdigit()  and start < end):\n",
    "                start +=1\n",
    "            while( not s[end].isalpha() and not s[end].isdigit() and start < end):\n",
    "                end -=1\n",
    "            if s[start].lower() != s[end].lower():\n",
    "                return False\n",
    "            else:\n",
    "                start +=1\n",
    "                end -=1\n",
    "    \n",
    "        return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        import re\n",
    "        r = ''.join(re.findall(r'[A-Za-z0-9]', s)).lower()\n",
    "        #print(len(r) // 2)\n",
    "        if r=='':\n",
    "            return True\n",
    "\n",
    "        else:\n",
    "            for i in range(len(r)-1,len(r)//2-1,-1):\n",
    "                print(r[i],r[len(r)-1-i])\n",
    "                if r[i]!=r[len(r)-1-i]:\n",
    "                    return False\n",
    "            return True\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: 'str') -> 'bool':\n",
    "        str_list=[]\n",
    "        for i in s:\n",
    "            if(i.isalnum()):\n",
    "                i=i.lower()\n",
    "                str_list.append(i)\n",
    "        return self.isHuiwen(str_list)\n",
    "    def isHuiwen(self,s):\n",
    "        lens=len(s)//2\n",
    "        for i in range(lens):\n",
    "            if(s[i]!=s[-i-1]):\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: 'str') -> 'bool':\n",
    "        if s == \"\":\n",
    "            return True\n",
    "        \n",
    "        s_list = [i.lower() for i in s if i.isalnum()]\n",
    "        \n",
    "        i = 0\n",
    "        j = len(s_list)-1\n",
    "        while i <j:\n",
    "            if s_list[i] == s_list[j]:\n",
    "                i+=1\n",
    "                j-=1\n",
    "            else:\n",
    "                return False\n",
    "        return True        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: 'str') -> 'bool':\n",
    "        res = []\n",
    "        for x in s:\n",
    "            if x.isdigit():\n",
    "                res.append(x)\n",
    "            elif x.isalpha():\n",
    "                res.append(x.lower())\n",
    "        return res == res[::-1]\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s):\n",
    "        \"\"\"\n",
    "        :type s: str\n",
    "        :rtype: bool\n",
    "        \"\"\"\n",
    "        # newbe了! python居然有一个isalnum()方法，直接检查一个字符是不是字母或者数字\n",
    "        purified_s = [i.lower() for i in s if i.isalnum()]\n",
    "        if purified_s[::-1] == purified_s:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        l=0\n",
    "        r=len(s)-1\n",
    "        while l<r:\n",
    "            while not s[l].isalnum() and l<r:\n",
    "                l+=1\n",
    "            while not s[r].isalnum() and l<r:\n",
    "                r-=1\n",
    "            if s[l].lower()==s[r].lower():\n",
    "                l+=1\n",
    "                r-=1\n",
    "            else:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        # import re\n",
    "        # s = re.sub(\"[^a-zA-Z0-9]\",'',s).lower()\n",
    "        # print(s , s[::-1])\n",
    "        # return s == s[::-1]\n",
    "        i, j = 0, len(s) - 1\n",
    "        while i < j:\n",
    "            while i < j and not s[i].isalnum():\n",
    "                i += 1\n",
    "            while i < j and not s[j].isalnum():\n",
    "                j -= 1\n",
    "            if s[i].lower() != s[j].lower():\n",
    "                return False\n",
    "            i, j = i + 1, j - 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        length = len(s)\n",
    "        if length == 0 or length == 1:\n",
    "            return True\n",
    "        low, high = 0, len(s) - 1\n",
    "        while low < high:\n",
    "            if not s[low].isalnum():\n",
    "                low += 1\n",
    "                continue\n",
    "            if not s[high].isalnum():\n",
    "                high -= 1\n",
    "                continue\n",
    "            if not s[low].lower() == s[high].lower():\n",
    "                return False\n",
    "            low += 1\n",
    "            high -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        left = 0\n",
    "        right = n - 1\n",
    "        while left < right:\n",
    "            while left < right and not s[left].isdigit() and not s[left].isalpha():  #既不是数字也不是字母，跳过\n",
    "                left += 1\n",
    "            while left < right and not s[right].isdigit() and not s[right].isalpha():\n",
    "                right -= 1\n",
    "            if left < right:\n",
    "                if s[left].lower() == s[right].lower(): #不区分大小写\n",
    "                    left += 1\n",
    "                    right -= 1\n",
    "                else:\n",
    "                    return False\n",
    "        return True\n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        # 空字符串 直接成功\n",
    "        if not s:\n",
    "            return True\n",
    "        else:\n",
    "            a = ''\n",
    "            for i in s:\n",
    "                ord_ = ord(i)\n",
    "                if 48 <= ord_ <= 57 or 65 <= ord_ <= 90 or 97 <= ord_ <= 122:\n",
    "                    a += i\n",
    "            else:\n",
    "                a = a.upper()\n",
    "                # n = len(a) // 2\n",
    "                # return a[0: n] == a[-1:-n - 1:-1]\n",
    "                return a == a[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        if not s:\n",
    "            return True\n",
    "        res = \"\"\n",
    "        for ss in s:\n",
    "            if ss.isalnum():\n",
    "                res += ss\n",
    "        res = res.lower()\n",
    "        print(\"res is:\", res)\n",
    "        reverse = res[::-1]\n",
    "        for i in range(len(res)):\n",
    "            if res[i] != reverse[i]:\n",
    "                return False\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s2 = ''.join([i for i in s if i.isalnum()]).lower()\n",
    "        return s2 == s2[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        l = list(s.lower())\n",
    "\n",
    "        i = 0\n",
    "        j = len(l)\n",
    "\n",
    "        while i < j:\n",
    "            if ((l[i]) < 'a' or l[i] > 'z') and (l[i] < '0' or l[i] > '9'):\n",
    "                i += 1\n",
    "                continue\n",
    "            if (l[j-1] < 'a' or l[j-1] > 'z') and (l[j-1] < '0' or l[j-1] > '9'):\n",
    "                j -= 1\n",
    "                continue\n",
    "           \n",
    "            if l[i] != l[j-1]:\n",
    "                return False\n",
    "            else:\n",
    "                i += 1\n",
    "                j -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        left, right = 0,len(s)-1\n",
    "\n",
    "        while left<right:\n",
    "            while left<right and not str.isalnum(s[left]):\n",
    "                left+=1\n",
    "            while left<right and not str.isalnum(s[right]):\n",
    "                right-=1\n",
    "            \n",
    "            while left<right :\n",
    "                if str.isalnum(s[right]) and str.isalnum(s[left]):\n",
    "                    if s[left].lower() != s[right].lower():\n",
    "                        return False\n",
    "                else:\n",
    "                    break\n",
    "        \n",
    "                left+=1\n",
    "                right-=1\n",
    "\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        i,j = 0,n-1\n",
    "        while i<j:\n",
    "            while i<j and not s[i].isalnum():\n",
    "                i += 1\n",
    "            while i<j and not s[j].isalnum():\n",
    "                j -= 1\n",
    "            if i < j:\n",
    "                if s[i].lower() != s[j].lower():\n",
    "                    return False\n",
    "                i += 1\n",
    "                j -= 1\n",
    "            else:\n",
    "                return True\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        left=0\n",
    "        right=len(s)-1\n",
    "        while left<right:\n",
    "            while left<right and not s[left].isalnum():\n",
    "                left+=1\n",
    "            while left<right and not s[right].isalnum():\n",
    "                right-=1\n",
    "            if left<right:\n",
    "                if s[left].lower()!=s[right].lower():\n",
    "                    return False\n",
    "                else:\n",
    "                    left+=1\n",
    "                    right-=1\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s=s.lower()\n",
    "        new_s=\"\"\n",
    "        for i in s:\n",
    "            if i.isalpha() or i.isdigit():\n",
    "               new_s+=i\n",
    "        if (new_s == '') or (new_s == new_s[::-1]):\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        strs=''\n",
    "        for i in s:\n",
    "            if i.isalnum():\n",
    "                strs+=i.lower()\n",
    "        print(strs)\n",
    "        if strs==strs[::-1]:\n",
    "            return True\n",
    "        else:\n",
    "            return False\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "\n",
    "        l,r = 0,len(s)-1\n",
    "\n",
    "        while l<r:\n",
    "            while l<r and not s[l].isalnum():\n",
    "                l += 1\n",
    "            while l<r and not s[r].isalnum():\n",
    "                r -= 1\n",
    "            if l<r:\n",
    "                if s[l].lower() != s[r].lower():\n",
    "                    return False\n",
    "                l += 1\n",
    "                r -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        left, right = 0, n - 1\n",
    "        \n",
    "        while left < right:\n",
    "            while left < right and not s[left].isalnum():\n",
    "                left += 1\n",
    "            while left < right and not s[right].isalnum():\n",
    "                right -= 1\n",
    "            if left < right:\n",
    "                if s[left].lower() != s[right].lower():\n",
    "                    return False\n",
    "                left, right = left + 1, right - 1\n",
    "\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        n = len(s)\n",
    "        l, r = 0, n-1\n",
    "        while l < r:\n",
    "            while l < r and not s[l].isalnum():\n",
    "                l += 1\n",
    "            while l < r and not s[r].isalnum():\n",
    "                r -= 1\n",
    "            if not s[l].lower() == s[r].lower():\n",
    "                return False\n",
    "            l += 1\n",
    "            r -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        result_1 = ''\n",
    "        result_2 = ''\n",
    "        for i in range(0, len(s)):\n",
    "            if s[i].isupper() or s[i].islower() or s[i].isdigit():\n",
    "                result_1 = result_1 + s[i]\n",
    "        for i in range(0, len(result_1)):\n",
    "            if result_1[i].isupper():\n",
    "                temp = result_1[i].lower()\n",
    "            else:\n",
    "                temp = result_1[i]\n",
    "            result_2 = result_2 + temp\n",
    "        s_demo = ''\n",
    "        for i in range(len(result_2) - 1, -1,-1):\n",
    "            s_demo = s_demo + result_2[i]\n",
    "        if result_2 == s_demo:\n",
    "            return True\n",
    "        return False\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        i = j = 0\n",
    "        s = list(s)\n",
    "        for j in range(len(s)):\n",
    "            if 65 <= ord(s[j]) <= 90:\n",
    "                s[j] = chr(ord(s[j]) + 32)\n",
    "                s[i] = s[j]\n",
    "            elif 97 <= ord(s[j]) <= 122 or 48 <= ord(s[j]) <= 57:\n",
    "                s[i] = s[j]\n",
    "            else:\n",
    "                continue\n",
    "            i += 1\n",
    "        end = i-1\n",
    "        i = 0\n",
    "        while i < end:\n",
    "            if s[i] != s[end]:\n",
    "                return False\n",
    "            i += 1\n",
    "            end -= 1\n",
    "        return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s = ''.join(filter(str.isalnum, s.lower()))\n",
    "        \n",
    "        right = len(s)-1\n",
    "        left = 0\n",
    "        if len(s)==0:\n",
    "            return True\n",
    "        else:\n",
    "            while right>left:\n",
    "                if s[left]!=s[right]:\n",
    "                    return False\n",
    "                else:\n",
    "                    right -= 1\n",
    "                    left += 1\n",
    "            return True\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        snew = re.sub(r'[^0-9a-zA-Z]+','',s).lower()\n",
    "        if not snew:\n",
    "            return True\n",
    "        sre = snew[::-1]\n",
    "        if sre == snew:\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        if s == \" \":\n",
    "            return True\n",
    "        # rst = \"\".join(re.findall(r\"[a-z|0-9]+\", s.lower()))\n",
    "        rst = re.sub(r\"\\W|_\", \"\", s.lower())\n",
    "        return rst == rst[::-1]    \n",
    "\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s = [i for i in s if i.isdigit() or i.isalpha()]\n",
    "        print(s)\n",
    "        end = len(s) - 1\n",
    "        start = 0\n",
    "\n",
    "        while start < end:\n",
    "            if s[start].lower() == s[end].lower():\n",
    "                start += 1\n",
    "                end -= 1\n",
    "            else:\n",
    "                return False\n",
    "\n",
    "        if start >= end:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        tmp = []\n",
    "        for r in s:\n",
    "            if r  >= '0' and r <= '9' or r >= 'a' and r <= 'z' :\n",
    "                tmp.append(r)\n",
    "            elif r >= 'A' and r <= 'Z':\n",
    "                tmp.append(r.lower())\n",
    "        return tmp == tmp[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        \n",
    "        \n",
    "        new_s  = s.lower()\n",
    "        list_new_s = list(new_s)\n",
    "        list_new_s = [value for value in list_new_s if ord('a') <= ord(value) and ord(value) <= ord('z') or value.isdigit()]\n",
    "        resver_s = list_new_s[::-1]\n",
    "        print(list_new_s)\n",
    "        print(resver_s)\n",
    "        return list_new_s==resver_s\n",
    "        \n",
    "    \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        right=len(s)-1\n",
    "        b=[]\n",
    "        c=[]\n",
    "        if s==' ':\n",
    "            return True\n",
    "        for i ,x in enumerate(s.lower()):\n",
    "            if (x>='a' and x <='z') or (x>='0' and x <='9'):\n",
    "                b.append(x)\n",
    "            if (s[right-i]>='a'and s[right-i]<='z') or (s[right-i]>='A' and s[right-i]<='Z') or (s[right-i]>='0'and s[right-i]<='9') : \n",
    "                c.append(s[right-i])\n",
    "        # return b,c\n",
    "        if str(b)==str(c).lower():\n",
    "            return True\n",
    "        else:\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        list1 = list()\n",
    "        for ch in s:\n",
    "            if ch >='a' and ch<='z':\n",
    "                list1.append(ch)\n",
    "            elif ch>='A' and ch<='Z':\n",
    "                list1.append(ch.lower())\n",
    "            elif ch>='0' and ch<='9':\n",
    "                list1.append(ch)\n",
    "        list2 = list()\n",
    "        for ch in s[::-1]:\n",
    "            if ch >='a' and ch<='z':\n",
    "                list2.append(ch)\n",
    "            elif ch>='A' and ch<='Z':\n",
    "                list2.append(ch.lower())\n",
    "            elif ch>='0' and ch<='9':\n",
    "                list2.append(ch)\n",
    "\n",
    "        for i in range(len(list1)):\n",
    "            if list1[i] != list2[i]:\n",
    "                return False\n",
    "        else:\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s1=list(s)\n",
    "        s2=[]\n",
    "        for ch in s1:\n",
    "            if ord('a')<=ord(ch)<=ord('z'):\n",
    "                s2.append(ch)\n",
    "            elif ord('0')<=ord(ch)<=ord('9'):\n",
    "                s2.append(ch)\n",
    "            elif ord('A')<=ord(ch)<=ord('Z'):\n",
    "                s2.append(ch.lower())\n",
    "        print(s2)\n",
    "        l=0\n",
    "        r=len(s2)-1\n",
    "        while l<r:\n",
    "            if s2[l]!=s2[r]:\n",
    "                return False\n",
    "            l+=1\n",
    "            r-=1\n",
    "        return True\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s1=list(s.lower())\n",
    "        new_li=[]\n",
    "        for i in s1:\n",
    "            if i.isdigit()==True or i.isalpha()==True:\n",
    "                new_li.append(i)\n",
    "        start_li=new_li.copy()\n",
    "        new_li.reverse()\n",
    "        print(str(new_li),str(start_li))\n",
    "        if str(new_li)==str(start_li):\n",
    "            return True\n",
    "        else:\n",
    "            print(False)\n",
    "            return False"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        sgood = \"\".join(ch.lower() for ch in s if ch.isalnum())\n",
    "        return sgood == sgood[::-1]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "\n",
    "        s = \"\".join(c.lower() for c in s if c.isalnum())\n",
    "        i = 0\n",
    "        j = len(s) - 1\n",
    "        while(i<j):\n",
    "            if s[i] != s[j]:\n",
    "                return False\n",
    "            i += 1\n",
    "            j -= 1\n",
    "        \n",
    "        return True\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        #把字母全部转小写,去除空格，数字不需要管，isalnum函数判断字符串是否都是字母\n",
    "        s = \"\".join(c.lower() for c in s if c.isalnum())\n",
    "        # i = 0\n",
    "        # j = len(s) - 1\n",
    "        # while(i<j):\n",
    "        #     if s[i] != s[j]:\n",
    "        #         return False\n",
    "        #     i += 1\n",
    "        #     j -= 1\n",
    "        \n",
    "        # return True\n",
    "        # return s==s[::-1]\n",
    "\n",
    "        #自己判断是否字母\n",
    "        s=s.lower()\n",
    "        new_s=''\n",
    "        for i in s:\n",
    "             if 'a' <= i <='z' or '0' <=i <='9':\n",
    "                new_s+=i\n",
    "        if (new_s=='') or (new_s==s[::-1]):return True \n",
    "        else: return False\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "\n",
    "        strfilt = []\n",
    "        if len(s) == 0:\n",
    "            return True\n",
    "        for s_i in s:\n",
    "            if s_i>='a' and s_i<='z':\n",
    "                strfilt.append(s_i.capitalize())\n",
    "            if s_i>='A' and s_i<='Z':\n",
    "                strfilt.append(s_i)\n",
    "            if s_i>=\"0\" and s_i<=\"9\":\n",
    "                strfilt.append(s_i)\n",
    "        if len(strfilt) == 1:\n",
    "            return True\n",
    "        \n",
    "        if len(strfilt)%2 == 0:\n",
    "            rcenter = len(strfilt)//2\n",
    "            while rcenter<len(strfilt):\n",
    "\n",
    "                if strfilt[rcenter] != strfilt[len(strfilt)-rcenter-1]:\n",
    "                    return False\n",
    "                rcenter+=1\n",
    "            return True\n",
    "        else:\n",
    "            rcenter = len(strfilt)//2+1\n",
    "            while rcenter<len(strfilt):\n",
    "                if strfilt[rcenter] != strfilt[len(strfilt)-rcenter-1]:\n",
    "                    return False\n",
    "                rcenter+=1\n",
    "            return True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        temp = []\n",
    "        for ss in s:\n",
    "            if ss.isalpha():\n",
    "                temp.append(ss.lower())\n",
    "            elif ss.isdigit():\n",
    "                temp.append(ss)\n",
    "        return temp == temp[::-1]\n",
    "\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        k=''.join(x.lower() for x in s if x.isalnum())\n",
    "        return k==k[::-1]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def isPalindrome(self, s: str) -> bool:\n",
    "        s = ''.join(c.lower() for c in s if c.isalnum())\n",
    "        return s[:len(s)] == s[::-1]\n"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
